package org.picommo.common;

import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Root;

@Root
public class Color {
	
	@Attribute
	public final int red;
	@Attribute
	public final int green;
	@Attribute
	public final int blue;
	@Attribute
	public final int alpha;
	
	
	public Color() {
		this(Color.BLACK);
	}
	
	public Color(Color c) {
		this(c.red, c.green, c.blue, c.alpha);
	}
	
	public Color(Color rgb, int alpha) {
		this(rgb.red, rgb.green, rgb.blue, alpha);
	}
	
	public Color(int red, int green, int blue) {
		this(red, green, blue, 255);
	}
	
	public Color(int red, int green, int blue, int alpha) {
		super();
		this.red = red;
		this.green = green;
		this.blue = blue;
		this.alpha = alpha;
	}
	
	
	public int getRed() {
		return red;
	}

	public int getGreen() {
		return green;
	}

	public int getBlue() {
		return blue;
	}

	public int getAlpha() {
		return alpha;
	}
	
	
	public int getSimilarityError(Color otherColor) {
		int redError = Math.abs(red - otherColor.red);
		int blueError = Math.abs(blue - otherColor.blue);
		int greenError = Math.abs(green - otherColor.green);
		
		return redError + blueError + greenError;
	}
	
	
	@Override
	public boolean equals(Object obj) {
		if(!(obj instanceof Color)) {
			return false;
		}
		
		Color c = (Color)obj;
		return c.red == red && c.green == green && c.blue == blue && c.alpha == alpha;
	}
	
	
	public static final Color BLACK = new Color(0, 0, 0, 255);
	public static final Color RED = new Color(255, 0, 0, 255);
	public static final Color GREEN = new Color(0, 255, 0, 255);
	public static final Color BLUE = new Color(0, 0, 255, 255);

}
